package com.wffz.controller;

import com.wffz.comm.api.ResponseResult;
import com.wffz.dto.MoneyDTO;
import com.wffz.po.ClientUser;
import com.wffz.po.UserCollectBank;
import com.wffz.service.UserCollectBankService;
import com.wffz.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.Date;
import java.util.List;

/**
 * @author sunlei
 * @className UserCollectBankController
 * @Description
 * @date 2023-02-28 19:28
 **/
@RestController
@Slf4j
@RequestMapping("/bank")
public class UserCollectBankController {

    @Resource
    private UserService userService;
    @Resource
    private UserCollectBankService userCollectBankService;

    @PostMapping("/saveBank")
    public ResponseResult saveBank(@RequestBody UserCollectBank userCollectBank, HttpServletRequest request) {
        Principal principal = request.getUserPrincipal();
        ClientUser clientUser = userService.findUserByUserName(principal.getName());
        userCollectBank.setUserId(clientUser.getId());
        userCollectBank.setLoginName(clientUser.getLoginName());
        userCollectBank.setCreateTime(new Date());
        boolean flag = userCollectBankService.saveUserCollectBankService(userCollectBank);
        return ResponseResult.success(flag);
    }


    @GetMapping("/bankList")
    public ResponseResult bankList(HttpServletRequest request) {
        Principal principal = request.getUserPrincipal();
        ClientUser ClientUser = userService.findUserByUserName(principal.getName());
        List<UserCollectBank> list = userCollectBankService.getBankList(ClientUser);
        return ResponseResult.success(list);
    }

}
